package com.chenjun.core.service.sys.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.chenjun.common.bean.Pagination;
import com.chenjun.common.model.DataGridModel;
import com.chenjun.common.model.DataGridSortModel;
import com.chenjun.core.dao.generator.entity.SysLog;
import com.chenjun.core.dao.generator.mapper.SysLogMapper;
import com.chenjun.core.dao.module.SysLogRelationMapper;
import com.chenjun.core.service.sys.SysLogService;
/**
 * 
 * @Description: 日志控制器
 * @author yanjinyin
 * @date 2017年7月29日 上午9:41:51
 */
@SuppressWarnings("serial")
@Service
@Transactional
public class SysLogServiceImpl  implements SysLogService {
    private static final Logger logger = Logger.getLogger(SysLogService.class);

    @Autowired
    private SysLogMapper sysLogMapper;
    
    @Autowired
    private SysLogRelationMapper sysLogRelationMapper;

	public SysLog get(String id){
		return sysLogMapper.selectByPrimaryKey(id);
	}

	public int create(SysLog record){
		return sysLogMapper.insert(record);
	}

	public int delete(String id){
		return sysLogMapper.deleteByPrimaryKey(id);
	}

	public int update(SysLog record){
		return sysLogMapper.updateByPrimaryKey(record);
	}

	public int createOrUpdate(SysLog record){
		int rows = 0;
		if (StringUtils.isBlank(record.getId())) {
			rows = sysLogMapper.insert(record);
		} else {
			rows = sysLogMapper.updateByPrimaryKeySelective(record);
		}
		return rows;
	}

	public int doCountByCondition(DataGridModel param){
		return sysLogRelationMapper.countByCondition(param);
	}

	public List<SysLog> doListByCondition(DataGridModel param){
		return sysLogRelationMapper.selectByCondition(param);
	}

	public Pagination doPagination(DataGridModel param){
		Pagination vo = new Pagination();
		DataGridSortModel sortModel=new DataGridSortModel("created_time", DataGridSortModel.DESC);
		List<DataGridSortModel> sortBy=new ArrayList<DataGridSortModel>();
		sortBy.add(sortModel);
		param.setSortBy(sortBy);
		List<SysLog> list = sysLogRelationMapper.selectByCondition(param);
		param.setStart(0);
		param.setRows(0);
		int size = sysLogRelationMapper.countByCondition(param);
		vo.setAaData(list);
		vo.setiTotalRecords(size);
		vo.setsEcho(param.getPage());
		vo.setiTotalDisplayRecords(size);
		return vo;
	}
}
